package com.iims.flowable_ui;

import lombok.extern.slf4j.Slf4j;
import org.flowable.ui.common.service.idm.RemoteIdmService;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.FilterType;
import org.springframework.core.env.Environment;

import javax.annotation.Resource;
import java.net.InetAddress;
import java.util.Arrays;

/**
 * @author Buderry
 */

@SpringBootApplication

@ComponentScan(basePackages = {
        "org.flowable.ui.modeler.conf",// flowable 开发环境内置的数据库连接
        "org.flowable.ui.modeler.repository",
        "org.flowable.ui.modeler.service",
        //"org.flowable.ui.modeler.security", //授权方面的都不需要
        //"org.flowable.ui.common.filter", // IDM 方面的过滤器
        "org.flowable.ui.common.service",
        "org.flowable.ui.common.repository",
        "org.flowable.ui.common.tenant"}, excludeFilters = {
        // 移除 RemoteIdmService
        @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = RemoteIdmService.class)})
@Slf4j
public class FlowableApplication extends SpringBootServletInitializer {
    @Resource
    private Environment environment;

    public static void main(String[] args) {
        SpringApplication.run(FlowableApplication.class, args);
    }

    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
        return super.configure(builder);
    }

    @Bean
    CommandLineRunner init() {
        return (args -> {
            log.info("=============== Active Profiles {} ===============",
                    Arrays.asList(environment.getActiveProfiles()).toString());
            log.info("Flowable App Address：http://{}:{}/flowable-ui",
                    InetAddress.getLocalHost().getHostAddress(), environment.getProperty("server.port"));
        });
    }
}
